//
//  StoreDetailMerchantWorksCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/2.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "StoreDetailMerchantWorksCell.h"
#import "StoreDetailWorksCollectionCell.h"

@interface StoreDetailMerchantWorksCell ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>{
    CGSize _cellSize;
    UIEdgeInsets _collectionEdge;
}

@end

@implementation StoreDetailMerchantWorksCell

+ (CGFloat)calculateHeight {
    return ceil(0.66 * ceil(240 * ADAPTER_WIDTH)) + 10;
}

- (void)fillCellWithArray:(NSMutableArray<CommonOpusModel *>*)dataArray {
    self.dataArray = dataArray;
    [self.collectionview reloadData];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    _cellSize =  CGSizeMake(ceil(240 * ADAPTER_WIDTH), ceil(0.66 * ceil(240 * ADAPTER_WIDTH)));
    _collectionEdge = UIEdgeInsetsMake(5, 12, 5, 12);
    
    UICollectionViewFlowLayout *flowLaout = [[UICollectionViewFlowLayout alloc]init];
    flowLaout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    

    self.collectionview.collectionViewLayout = flowLaout;
    self.collectionview.delegate = self;
    self.collectionview.dataSource = self;
    self.collectionview.showsHorizontalScrollIndicator = NO;
    self.collectionview.showsVerticalScrollIndicator = NO;
    
    [self.collectionview registerNib:[UINib nibWithNibName:@"StoreDetailWorksCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"StoreDetailWorksCollectionCellID"];
}

- (void)fillCellWithModel {
    
    [self.collectionview reloadData];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    StoreDetailWorksCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"StoreDetailWorksCollectionCellID" forIndexPath:indexPath];
    [cell fillCellWithModel:self.dataArray[indexPath.row]];
    return cell;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    return _cellSize;
}

//设置cell的位置
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView
                       layout:(UICollectionViewLayout *)collectionViewLayout
       insetForSectionAtIndex:(NSInteger)section {

    return _collectionEdge;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 10;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

    if (self.StoreDetailMerchantWorksCellBlock) {
        self.StoreDetailMerchantWorksCellBlock(indexPath.row);
    }
}



@end
